<?php
/***********************************************************
	Filename: app/www/control/usercp.php
	Note	: 用户控制面板
	Version : 3.0
	Author  : qinggan
	Update  : 2010-05-04
***********************************************************/
class usercp_c extends Control
{
	function __construct()
	{
		parent::Control();
		$this->load_model("user");
	}

	function usercp_c()
	{
		$this->__construct();
	}

	function index_f()
	{
		if(!$_SESSION["user_id"])
		{
			error("非会员不允许执行此操作",site_url("login"));
		}
		$rs = $this->user_m->user_from_id($_SESSION["user_id"]);
		$this->tpl->assign("rs",$rs);

		$sitetitle = "修改资料 - 个人中心";
		$this->tpl->assign("sitetitle",$sitetitle);
		$array[0]["title"] = "个人中心";
		$array[0]["url"] = site_url("usercp");
		$array[1]["title"] = "修改资料";
		$this->tpl->assign("leader",$array);


		$this->tpl->display("usercp_info.".$this->tpl->ext);
	}

	//存储个人信息
	function info_f()
	{
		if(!$_SESSION["user_id"])
		{
			error("非会员不允许执行此操作",site_url("login"));
		}
		$array = array();
		$array["email"] = $this->trans_lib->safe("email");
		$array["mobile"] = $this->trans_lib->safe("mobile");
		$array["tel"] = $this->trans_lib->safe("tel");
		$array["msn"] = $this->trans_lib->safe("msn");
		$array["qq"] = $this->trans_lib->safe("qq");
		if(!$array["email"])
		{
			error("会员邮箱不允许为空！",site_url("usercp"));
		}
		$this->user_m->update_info($array,$_SESSION["user_id"]);
		error("会员信息更新完毕！",site_url("usercp"));
	}

	function pass_f()
	{
		if(!$_SESSION["user_id"])
		{
			error("非会员不允许执行此操作",site_url("login"));
		}
		$sitetitle = "修改个人密码 - 个人中心";
		$this->tpl->assign("sitetitle",$sitetitle);
		$array[0]["title"] = "个人中心";
		$array[0]["url"] = site_url("usercp");
		$array[1]["title"] = "修改个人密码";
		$this->tpl->assign("leader",$array);
		$this->tpl->display("usercp_pass.".$this->tpl->ext);
	}

	function passok_f()
	{
		if(!$_SESSION["user_id"])
		{
			error("非会员不允许执行此操作",site_url("login"));
		}
		$rs = $this->user_m->user_from_id($_SESSION["user_id"]);
		$old = $this->trans_lib->safe("oldpass");
		$new = $this->trans_lib->safe("newpass");
		$chk = $this->trans_lib->safe("chkpass");
		if(!$old || sys_md5($old) != $rs["pass"])
		{
			error("旧密码为空或是旧密码填写不正确",site_url("usercp,pass"));
		}
		if(!$new || $new != $chk)
		{
			error("新密码不允许为空或是两次输入的新密码不一致！",site_url("usercp,pass"));
		}
		if($new == $old)
		{
			error("新旧密码一致，不需要修改！",site_url("usercp,pass"));
		}
		//更新密码
		$this->user_m->update_pass(sys_md5($new),$_SESSION["user_id"]);
		error("密码已经更新成功，下次请用新密码登录。",site_url("usercp,pass"));
	}
}
?>